﻿using System;

namespace Mbs.Messaging
{
    /// <summary>
    /// 消息总线接口
    /// </summary>
    public interface IMessageBus : IPublisher,IDisposable
    {
        /// <summary>
        /// 发布消息
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="message"></param>
        void Publish<TMessage>(TMessage message);

        /// <summary>
        /// 发布消息
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="sender"></param>
        /// <param name="message"></param>
        void Publish<TMessage>(object sender, TMessage message);

        /// <summary>
        /// 发布主题消息
        /// </summary>
        /// <param name="topic">消息主题</param>
        /// <param name="sender"></param>
        /// <param name="msg"></param>
        void Publish(string topic, object sender, object msg);

        /// <summary>
        /// 发布主题消息
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="topic"></param>
        /// <param name="message"></param>
        void Publish<TMessage>(string topic, TMessage message);

        /// <summary>
        /// 发布主题消息
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="topic"></param>
        /// <param name="sender"></param>
        /// <param name="message"></param>
        void Publish<TMessage>(string topic,object sender, TMessage message);

        /// <summary>
        /// 订阅消息
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="handler"></param>
        /// <returns></returns>
        IDisposable Subscribe<TMessage>(ObserverHandler<TMessage> handler);

        /// <summary>
        /// 订阅主题消息
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="topic"></param>
        /// <param name="handler"></param>
        /// <returns></returns>
        IDisposable Subscribe<TMessage>(string topic, ObserverHandler<Topic<TMessage>> handler);
        /// <summary>
        /// 注销订阅的消息
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="handler"></param>
        void Unsubscribe<TMessage>(ObserverHandler<TMessage> handler);

        /// <summary>
        /// 注销订阅的主题消息
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="topic">消息主题</param>
        /// <param name="handler"></param>
        void Unsubscribe<TMessage>(string topic, ObserverHandler<Topic<TMessage>> handler);

        /// <summary>
        /// 订阅消息的前置过滤器
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="handler"></param>
        /// <returns></returns>
        IDisposable SubscribePreFilter<TMessage>(PreFilterHandler<TMessage> handler);

        /// <summary>
        /// 订阅主题消息的前置过滤器
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="topic"></param>
        /// <param name="handler"></param>
        /// <returns></returns>
        IDisposable SubscribePreFilter<TMessage>(string topic, PreFilterHandler<Topic<TMessage>> handler);

        /// <summary>
        /// 取消订阅的消息前置过滤器
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="handler"></param>
        void UnsubscribePreFilter<TMessage>(PreFilterHandler<TMessage> handler);

        /// <summary>
        /// 取消订阅的主题消息前置过滤器
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="topic"></param>
        /// <param name="handler"></param>
        void UnsubscribePreFilter<TMessage>(string topic, PreFilterHandler<Topic<TMessage>> handler);

        /// <summary>
        /// 订阅消息过滤器
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="handler"></param>
        /// <returns></returns>
        IDisposable SubscribeFilter<TMessage>(FilterHandler<TMessage> handler);

        /// <summary>
        /// 订阅主题消息过滤器
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="topic"></param>
        /// <param name="handler"></param>
        /// <returns></returns>
        IDisposable SubscribeFilter<TMessage>(string topic, FilterHandler<Topic<TMessage>> handler);

        /// <summary>
        /// 取消订阅消息过滤器
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="handler"></param>
        void UnsubscribeFilter<TMessage>(FilterHandler<TMessage> handler);

        /// <summary>
        /// 取消订阅主题消息过滤器
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="topic"></param>
        /// <param name="handler"></param>
        void UnsubscribeFilter<TMessage>(string topic,  FilterHandler<Topic<TMessage>> handler);

        /// <summary>
        /// 注册消息监听器
        /// </summary>
        /// <param name="listners"></param>
        void RegisterListner(params ISimpleMessageListner[] hks);
        /// <summary>
        /// 注销消息监听器
        /// </summary>
        /// <param name="listners"></param>
        void UnRegisterListner(params ISimpleMessageListner[] hks);

        /// <summary>
        /// 移除消息
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        void Remove<TMessage>();
        /// <summary>
        /// 移除主题消息
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="topic"></param>
        void Remove<TMessage>(string topic);
        /// <summary>
        /// 移除消息
        /// </summary>
        /// <param name="type"></param>
        void Remove(Type type);
        /// <summary>
        /// 移除主题消息
        /// </summary>
        /// <param name="topic"></param>
        /// <param name="type"></param>
        void Remove(string topic, Type type);
    }
}